Sorting Grid Entries
The property grid can be sorted in the following ways:
- By setting the Sorting property to a suitable IComparer. The PropertySorting class contains a predefined IComparer for the common sort-by-name scenario:
<ms:PropertyGrid Sorting='{x:Static ms:PropertySorting.ByHumanName}'/>
- By setting the CustomSort property of the default view of the BindingView property. (You will need to cast to a ListCollectionView.)
- By applying a SortDescription to the default view of the BindingView property, as follows:
1SortDescription alphabetical = new SortDescription("Node.HumanName", ListSortDirection.Ascending); 2ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView); 3view.SortDescriptions.Add(alphabetical);
If an instance of the grid contains expanding nodes, sort descriptions are not propagated to child nodes (but custom sorts are). To sort a set of children if you are using SortDescriptions, locate the parent in the BindingView collection, and apply a SortDescription to the default view of its Children property.
Filtering Grid Entries
The property grid can be filtered by setting the Filter property of the default view of the BindingView property, as follows:
1ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView); 2view.Filter = delegate(object obj) 3{ 4 Node node = ((PropertyGridRow)obj).Node; 5 return node.Children.Count == 0; 6};
Grouping Grid Entries
Properties can be grouped in the following ways:
- By setting the Grouping property to a suitable GroupDescription. The PropertyGrouping class contains a predefined GroupDescription for the common group-by-category scenario:
<ms:PropertyGrid Grouping='{x:Static ms:PropertyGrouping.ByCategory}'/>
- By applying a GroupDescription to the default view of the BindingView property, as follows:
1PropertyGroupDescription byCategory = new PropertyGroupDescription("Node", new NodeToCategoryConverter()); 2ICollectionView view = CollectionViewSource.GetDefaultView(PropertyGrid1.BindingView); 3view.GroupDescriptions.Add(byCategory);
Built-In Support
The property grid control can optionally display a toolbar with commands for sorting alphabetically and grouping by category (using CategoryAttribute), and a search/filter facility. To display this toolbar, set the IsToolBarVisible property of the grid instance to true.